Skip to content

Conversation

@jacksjm
Copy link
Owner

@jacksjm jacksjm commented Oct 3, 2020

Solutions for Chapter 3

cc @vrom911 @chshersh

Copy link

@vrom911 vrom911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's neat work 👌🏼 Congrats on finishing Chapter 3 🥇

{ bookTitle :: String
, bookAutor :: String
, bookPages :: Int
, bookPrice :: Int
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤑 💰

Create a simple enumeration for the meal types (e.g. breakfast). The one who
comes up with the most number of names wins the challenge. Use your creativity!
-}
data Meal = Breakfast | Frühstück | Brunch | Lunch | Dinner | Supper | Snack | OnlyWater
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧀 🍨 🧊
These are new! Would need to add Frühstück into my schedule 😄

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the second German breakfast 🥳

, cityHouses :: [House]
}

data Castle = None | OnlyCastle | CastleWithWalls
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task tells that the castle should have a name. In this case, it can be a String.
Sorry, if it wasn't clear before. 😞 We improved this task wording in the latest version to clarify this moment.

Could you guess, what functions would need patching in case of the type modifications? 🙂

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had read: Optional castle with a name, sorry. I'll try

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, it's our bad that the wording wasn't clear!

buildWalls :: City -> City
buildWalls city = case cityCastle city of
OnlyCastle ->
if sum (map countPeople (cityHouses city)) >= 10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice combination of the standard functions 👍🏼

let damage = calculatePlayerDamage (playerAttack player2) (playerStrength player2)
defense = calculatePlayerDefense (playerArmor player1) (playerDexterity player1)
newHealth = calculatePlayerHit damage defense (playerHealth player1)
in player1 { playerHealth = newHealth }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on newtypes! 🏅 Newtypes are one very important feature in Haskell 👍

| otherwise = succ weekday

daysToParty :: Weekday -> Int
daysToParty weekday = fromEnum Fri - fromEnum weekday
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would show the shortest distance to Friday, however, time doesn't work like this.
For example. if it is Saturday, it would tell you that it is -1 day to Friday, however, it is 6 days to go 🥳

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the regular order of days because of this, but I am aware that this is a cheat 😰

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this one way to do it, but I agree, that this looks like a cheat 😄

You can apply the knowledge that we know exactly that there are 7 days in a week. So we can just calculate everything by mod 7!

Let's look how it would work:

ghci> mod (5) 7
5
ghci> mod (-1) 7
6

Looks like just what we need!

@jacksjm jacksjm added the hacktoberfest-accepted Accepted for hacktoberfest, will merge later label Oct 3, 2020
@jacksjm jacksjm changed the title feat: solution chapter 3 feat: solutions chapter 3 Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted Accepted for hacktoberfest, will merge later

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants